angular.module('starter.controllers', [])

.controller('AppCtrl', function ($scope, $ionicModal, $timeout) {

    // With the new view caching in Ionic, Controllers are only called
    // when they are recreated or on app start, instead of every page change.
    // To listen for when this page is active (for example, to refresh data),
    // listen for the $ionicView.enter event:
    //$scope.$on('$ionicView.enter', function(e) {
    //});

    // Form data for the login modal
    $scope.loginData = {};

    // Create the login modal that we will use later
    $ionicModal.fromTemplateUrl('templates/login.html', {
        scope: $scope
    }).then(function (modal) {
        $scope.modal = modal;
    });

    // Triggered in the login modal to close it
    $scope.closeLogin = function () {
        $scope.modal.hide();
    };

    // Open the login modal
    $scope.login = function () {
        $scope.modal.show();
    };

    // Perform the login action when the user submits the login form
    $scope.doLogin = function () {
        console.log('Doing login', $scope.loginData);

        // Simulate a login delay. Remove this and replace with your login
        // code if using a login system
        $timeout(function () {
            $scope.closeLogin();
        }, 1000);
    };
})



.controller('DashCtrl', function ($scope) { })

.controller('ChatsCtrl', function ($scope, Chats) {
    // With the new view caching in Ionic, Controllers are only called
    // when they are recreated or on app start, instead of every page change.
    // To listen for when this page is active (for example, to refresh data),
    // listen for the $ionicView.enter event:
    //
    //$scope.$on('$ionicView.enter', function(e) {
    //});

    $scope.chats = Chats.all();
    $scope.remove = function (chat) {
        Chats.remove(chat);
    };
})

.controller('ChatDetailCtrl', function ($scope, $stateParams, Chats) {
    $scope.chat = Chats.get($stateParams.chatId);
})

.controller('AccountCtrl', function ($scope) {
    $scope.settings = {
        enableFriends: true
    };
})
.controller('MainCtrl', function ($scope,USHolidayService) {
    $scope.GetCountriesAvailable = function () {
        $scope.isCities = true;
        debugger;
        var s = USHolidayService.GetCountriesAvailable();
        console.log(s);
        $scope.cities = s;
        //USHolidayService.abc(
        //  function (response) {
        //     // debugger;
        //      //var x2js = new X2JS();
        //      //var jsonObj = x2js.xml_str2json(response);
        //      $scope.cities = response; // jsonObj.NewDataSet.Table;
              
        //  }, function () {
        //      console.warn("Something went wrong!");
        //  }
        //);
    };
})
.controller('MenuForm1Ctrl', function ($state,$scope, $timeout, $ionicLoading,$location) {
    $ionicLoading.show({
        content: 'Loading',
        animation: 'fade-in',
        showBackdrop: true,
        maxWidth: 200,
        showDelay: 0
    });

    $timeout(function () {
        $ionicLoading.hide();
        $scope.items = [
            { id: 1, text: "111111", url: "img/ionic.png" }, { id: 2, text: "222222", url: "img/adam.jpg" }, { id: 3, text: "333333", url: "img/ben.png" },
            { id: 4, text: "444444", url: "img/max.png" }, { id: 5, text: "555555", url: "img/mike.png" }, { id: 6, text: "666666", url: "img/perry.png" },
            { id: 7, text: "777777", url: "img/ionic.png" }, { id: 8, text: "888888", url: "img/ionic.png" }, { id: 9, text: "999999", url: "img/ionic.png" },
            { id: 10, text: "aaaaaa", url: "img/ionic.png" }, { id: 11, text: "bbbbbb", url: "img/ionic.png" }, { id: 12, text: "cccccc", url: "img/ionic.png" },
        ];
    }, 2000);

    $scope.alertClick = function (val) {
        alert(val);
    };
    $scope.click = function (val) {
        debugger;
        if (val = "333333") {
            $state.go("tab.MenuForm2");
            //$location.path("tab/MenuForm2.html");
            var curUrl = $location.absUrl();
            return;
            }
        else
            return;
    };

})

.controller('MenuForm2Ctrl', function ($scope, $timeout, $ionicLoading) {
    $ionicLoading.show({
        content: 'Loading',
        animation: 'fade-in',
        showBackdrop: true,
        maxWidth: 200,
        showDelay: 0
    });

    $timeout(function () {
        $ionicLoading.hide();
        $scope.items = [
            { id: 1, text: "111111", url: "img/ionic.png" }, { id: 2, text: "222222", url: "img/adam.jpg" }, { id: 3, text: "333333", url: "img/ben.png" },
            { id: 4, text: "444444", url: "img/max.png" }, { id: 5, text: "555555", url: "img/mike.png" }, { id: 6, text: "666666", url: "img/perry.png" },
            { id: 7, text: "777777", url: "img/ionic.png" }, { id: 8, text: "888888", url: "img/ionic.png" }, { id: 9, text: "999999", url: "img/ionic.png" },
            { id: 10, text: "aaaaaa", url: "img/ionic.png" }, { id: 11, text: "bbbbbb", url: "img/ionic.png" }, { id: 12, text: "cccccc", url: "img/ionic.png" },
        ];
    }, 2000);

    $scope.alertClick = function (val) {
        alert(val);

        $scope.click = function (val) {

        };
    }
})

;